package com.liuyh.demo.serviceserver.Controller.test;

import org.apache.commons.lang.math.RandomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
@RequestMapping("compute")
public class ComputeController {

    private static Logger logger = LoggerFactory.getLogger(ComputeController.class);

    @RequestMapping(method = RequestMethod.POST,value = "/add")
    public @ResponseBody int add(int a, int b){
        try {
            logger.debug("sleeping ...................");
            Thread.sleep(RandomUtils.nextInt(1000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return a + b ;
    }

    @RequestMapping(method = RequestMethod.POST,value = "/decrease")
    public @ResponseBody int decrease(int a, int b){
        try {
            logger.debug("sleeping ...................");
            Thread.sleep(RandomUtils.nextInt(1000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return a - b ;
    }

}
